<template>
	<view>

	</view>
</template>

<script>
	import {
		getAction,
		postAction,
		putAction
	} from '@/api/api.js'
	import config from '@/api/config.js'
	export default {
		data() {
			return {
				uri: '',
				redirect_uri: 'http%3A%2F%2Fregister.ydyjk.com.cn',
				code: '',
				wx_appid: 'wx49ad1b4481e6b941'
			}
		},
		onLoad() {

			if (window.location.search != null && window.location.search.length > 0) {
				this.redirect_uri = this.redirect_uri + window.location.search
				this.getwxCode()
			} else {
				uni.$u.toast("请重新扫码进入");
			}

		},
		methods: {
			getwxCode() {
				let currentUrl = window.location.href
				this.uri = currentUrl
				if (currentUrl.indexOf("&code=") === -1) {
					window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + this.wx_appid +
						"&redirect_uri=" + this.redirect_uri +
						"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
				} else {
					let arr = this.uri.split("?")
					if (arr.length > 1) {
						let arr1 = arr[1].split("&")
						let arr2 = arr1[1].split("=")
						let str = arr2[1]
						this.code = str
						this.getwxopenid()
					}
				}
			},

			getwxopenid() {
				getAction("/carRegister/carRegister/m/getOpenid?code=" + this.code).then(res => {
					if (res.success) {

						let param = window.location.search.split('?')[1]
						let id = param.split("&")[0].split("=")[1]
						if (decodeURIComponent(id.substring(0, id.length - 1)) == "天津太维信息科技有限公司") {
							return this.pageto()
						}
						let location = decodeURIComponent(id.substring(0, id.length - 1));
						let leadingEnterprise = id.substring(id.length - 1)
						
						if (location == "英格瓷(天津)新材料技术有限公司") {
							location = "英格瓷（天津）新材料技术有限公司"
						}
						uni.setStorageSync("openId", res.result)
						uni.setStorageSync("location", location)
						uni.setStorageSync("leadingEnterprise", leadingEnterprise)

						this.pageto()


					} else {
						uni.$u.toast("请重新扫码进入");
					}
				})
			},
			pageto() {
				/* 	uni.navigateTo({
						url:""
					}) */
			},
		}
	}
</script>

<style>

</style>
